package com.example.tellwin.mine.act;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.tellwin.MainApplication;
import com.example.tellwin.R;
import com.example.tellwin.base.CpBaseActivty;
import com.example.tellwin.base.DaggerRxComponent;
import com.example.tellwin.common.Common;
import com.example.tellwin.mine.bean.GradeBean;
import com.example.tellwin.mine.bean.MandarinBeam;
import com.example.tellwin.mine.bean.QualificationBean;
import com.example.tellwin.mine.bean.SubjectBean;
import com.example.tellwin.mine.bean.UserContentBean;
import com.example.tellwin.mine.bean.UserInfo;
import com.example.tellwin.mine.contract.MineDetailContract;
import com.example.tellwin.mine.presenter.MineDetailPresenter;
import com.example.tellwin.utils.CommonUtils;
import com.example.tellwin.utils.GlideUtils;
import com.example.tellwin.utils.ImageUtils;
import com.example.tellwin.utils.ToastUtil;
import com.example.tellwin.view.AddressDialog;
import com.example.tellwin.view.SelectListDialog;
import com.example.tellwin.view.SelectWheelDialog;
import com.example.tellwin.view.TakePhotoDialog;
import com.google.gson.JsonObject;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.example.tellwin.common.Common.PhotoAlbumRequestCode;
import static com.example.tellwin.common.Common.TakePhotoRequestCode;

public class MineDetailActivity extends CpBaseActivty implements MineDetailContract.View, TextWatcher {
    /*学生*/
    @BindView(R.id.student_nickname_et)
    EditText studentNicknameEt;
    @BindView(R.id.student_grade_tv)
    TextView studentGradeTv;
    @BindView(R.id.student_man_rbtn)
    RadioButton studentManRbtn;
    @BindView(R.id.student_women_rbtn)
    RadioButton studentWomenRbtn;
    @BindView(R.id.student_sex_rb)
    RadioGroup studentSexRb;
    @BindView(R.id.student_location_tv)
    TextView studentLocationTv;
    @BindView(R.id.student_scholl_et)
    EditText studentSchollEt;
    @BindView(R.id.student_detail_ll)
    LinearLayout studentDetailLl;
    /*解答人*/
    @BindView(R.id.answer_name_et)
    EditText answerNameEt;
    @BindView(R.id.answer_location_tv)
    TextView answerLocationTv;
    @BindView(R.id.answer_scholl_et)
    EditText answerSchollEt;
    @BindView(R.id.answer_grade_tv)
    TextView answerGradeTv;
    @BindView(R.id.answer_detail_ll)
    LinearLayout answerDetailLl;
    @BindView(R.id.good_at_subjects_tv)
    TextView goodAtSubjectsTv;
    @BindView(R.id.education_time_et)
    EditText educationTimeEt;
    @BindView(R.id.answer_qualification_tv)
    TextView answerQualificationTv;
    @BindView(R.id.pu_tong_hua_tv)
    TextView puTongHuaTv;
    @BindView(R.id.answer_man_rbtn)
    RadioButton answerManRbtn;
    @BindView(R.id.answer_women_rbtn)
    RadioButton answerWomenRbtn;
    @BindView(R.id.answer_sex_rb)
    RadioGroup answerSexRb;
    @BindView(R.id.answer_detail_2_ll)
    LinearLayout answerDetail2Ll;
    /*老师*/
    @BindView(R.id.teacher_name_et)
    EditText teacherNameEt;
    @BindView(R.id.teacher_location_tv)
    TextView teacherLocationTv;
    @BindView(R.id.teacher_scholl_et)
    EditText teacherSchollEt;
    @BindView(R.id.teacher_grade_tv)
    TextView teacherGradeTv;
    @BindView(R.id.teacher_good_at_subjects_tv)
    TextView teacherGoodAtSubjectsTv;
    @BindView(R.id.teacher_education_time_et)
    EditText teacherEducationTimeEt;
    @BindView(R.id.teacher_qualification_tv)
    TextView teacherQualificationTv;
    @BindView(R.id.teacher_pu_tong_hua_tv)
    TextView teacherPuTongHuaTv;
    @BindView(R.id.teacher_man_rbtn)
    RadioButton teacherManRbtn;
    @BindView(R.id.teacher_women_rbtn)
    RadioButton teacherWomenRbtn;
    @BindView(R.id.teacher_sex_rb)
    RadioGroup teacherSexRb;
    @BindView(R.id.teacher_detail_ll)
    LinearLayout teacherDetailLl;

    @BindView(R.id.remark_text)
    TextView remarkText;
    @BindView(R.id.remark_et)
    EditText remarkEt;
    @BindView(R.id.remark_ll)
    RelativeLayout remarkLl;
    @BindView(R.id.head_photo_iv)
    ImageView headPhotoIv;
    @BindView(R.id.confrim_btn)
    TextView confrimBtn;

    TakePhotoDialog takePhotoDialog;
    SelectWheelDialog gradeDialog;
    SelectListDialog hierarchyDialog;
    SelectWheelDialog subjectDialog;
    AddressDialog addressDialog;
    List<GradeBean> gradeList = new ArrayList<>();
    List<SubjectBean> subjectList = new ArrayList<>();
    List<QualificationBean> qualificationBeans = new ArrayList<>();
    List<MandarinBeam> mandarinBeams = new ArrayList<>();

    private int type;
    private UserContentBean userContentBean;
    private String localPath;

    @Inject
    MineDetailPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_detail);
        ButterKnife.bind(this);
        initViews();
        initEvents();
        initDatas();
    }

    @Override
    protected void initViews() {
        DaggerRxComponent.builder()
                .baseAppComponent(MainApplication.getAppComponent())
                .build()
                .inject(this);
        mPresenter.attachView(this);
    }

    @Override
    protected void initEvents() {
        answerGradeTv.setOnClickListener(v -> showGradeDailog());
        studentGradeTv.setOnClickListener(v -> showGradeDailog());
        teacherGradeTv.setOnClickListener(v -> showGradeDailog());
        puTongHuaTv.setOnClickListener(v -> showHierarchyDialog(puTongHuaTv, new ArrayList<>(mandarinBeams), 1));
        teacherPuTongHuaTv.setOnClickListener(v -> showHierarchyDialog(teacherPuTongHuaTv, new ArrayList<>(mandarinBeams), 1));
        answerQualificationTv.setOnClickListener(v -> showHierarchyDialog(answerQualificationTv, new ArrayList<>(qualificationBeans), 2));
        teacherQualificationTv.setOnClickListener(v -> showHierarchyDialog(teacherQualificationTv, new ArrayList<>(qualificationBeans), 2));
        goodAtSubjectsTv.setOnClickListener(v -> showSubjectDialog());
        teacherGoodAtSubjectsTv.setOnClickListener(v -> showSubjectDialog());
        studentLocationTv.setOnClickListener(v -> showAddressDialog());
        answerLocationTv.setOnClickListener(v -> showAddressDialog());
        teacherLocationTv.setOnClickListener(v -> showAddressDialog());
        studentNicknameEt.addTextChangedListener(this);
        teacherNameEt.addTextChangedListener(this);
        answerNameEt.addTextChangedListener(this);
        remarkEt.addTextChangedListener(this);
        educationTimeEt.addTextChangedListener(this);
        answerSchollEt.addTextChangedListener(this);
        studentSchollEt.addTextChangedListener(this);
        teacherSchollEt.addTextChangedListener(this);
        teacherEducationTimeEt.addTextChangedListener(this);
        studentSexRb.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.student_man_rbtn) {
                userContentBean.getUserInfo().setGender(1);
            } else {
                userContentBean.getUserInfo().setGender(2);
            }
            setConfrimBtnEnable();
        });
        teacherSexRb.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.teacher_man_rbtn) {
                userContentBean.getUserInfo().setGender(1);
            } else {
                userContentBean.getUserInfo().setGender(2);
            }
            setConfrimBtnEnable();
        });
        answerSexRb.setOnCheckedChangeListener((group, checkedId) -> {
            if (checkedId == R.id.answer_man_rbtn) {
                userContentBean.getUserInfo().setGender(1);
            } else {
                userContentBean.getUserInfo().setGender(2);
            }
            setConfrimBtnEnable();
        });
    }

    @Override
    protected void initDatas() {
        mPresenter.getGradeList();
        userContentBean = (UserContentBean) getIntent().getSerializableExtra(Common.USERINFO);
        type = getIntent().getIntExtra(Common.TYPE, 0);
        if (userContentBean.getUserInfo().getUserIdentity() == 2 || type == Common.ApplyAnswer) {
            mPresenter.getQualificationsList();
            mPresenter.getSubjectList();
            mPresenter.getMandarinList();
        }
        if (userContentBean == null) {
            ToastUtil.show(this, R.string.get_user_info_error);
            finish();
            return;
        }
        UserInfo userInfo = userContentBean.getUserInfo();
        GlideUtils.LoadImage(this, userInfo.getHeadPic(), headPhotoIv, R.mipmap.pic_a);
        if (type == Common.ApplyAnswer) {
            setTitle(R.string.apple_answer_person);
            studentDetailLl.setVisibility(View.GONE);
            teacherDetailLl.setVisibility(View.GONE);
            answerDetailLl.setVisibility(View.VISIBLE);
            answerDetail2Ll.setVisibility(View.VISIBLE);

            answerNameEt.setText(CommonUtils.getStr(userInfo.getNickName()));
            answerLocationTv.setText(CommonUtils.getStr(userInfo.getProvince()) + CommonUtils.getStr(userInfo.getCity()) + CommonUtils.getStr(userInfo.getArea()));
            answerSchollEt.setText(CommonUtils.getStr(userInfo.getSchool()));
            answerGradeTv.setText(CommonUtils.getStr(userInfo.getGradeName()));
            goodAtSubjectsTv.setText(CommonUtils.getStr(userInfo.getSubjectName()));
            educationTimeEt.setText(CommonUtils.getStr(userInfo.getYears()));
            answerQualificationTv.setText(CommonUtils.getStr(userInfo.getQualificationsName()));
            puTongHuaTv.setText(CommonUtils.getStr(userInfo.getMandarinName()));
            remarkText.setText("自我描述：");
            if(!TextUtils.isEmpty(userInfo.getDescribe())){
                remarkEt.setText(userInfo.getDescribe());
            }else {
                remarkEt.setText(CommonUtils.getStr(userInfo.getRemarks()));
            }
            if (userInfo.getGender() == 1) {
                answerSexRb.check(R.id.answer_man_rbtn);
            } else if (userInfo.getGender() == 2) {
                answerSexRb.check(R.id.answer_women_rbtn);
            }
        } else if (userContentBean.getUserInfo().getUserIdentity() == 1) {
            studentDetailLl.setVisibility(View.VISIBLE);
            answerDetailLl.setVisibility(View.GONE);
            answerDetail2Ll.setVisibility(View.GONE);
            teacherDetailLl.setVisibility(View.GONE);
            remarkEt.setText(userInfo.getRemarks());
            studentNicknameEt.setText(CommonUtils.getStr(userInfo.getNickName()));
            studentGradeTv.setText(CommonUtils.getStr(userInfo.getGradeName()));
            if (userInfo.getGender() == 1) {
                studentSexRb.check(R.id.student_man_rbtn);
            } else if (userInfo.getGender() == 2) {
                studentSexRb.check(R.id.student_women_rbtn);
            }
            studentLocationTv.setText(CommonUtils.getStr(userInfo.getProvince()) + CommonUtils.getStr(userInfo.getCity()) + CommonUtils.getStr(userInfo.getArea()));
            studentSchollEt.setText(CommonUtils.getStr(userInfo.getSchool()));
            setTitle(R.string.student_detail);
        } else if (userContentBean.getUserInfo().getUserIdentity() == 2) {
            setTitle(R.string.teacher_detail);
            teacherDetailLl.setVisibility(View.VISIBLE);
            studentDetailLl.setVisibility(View.GONE);
            answerDetailLl.setVisibility(View.GONE);
            answerDetail2Ll.setVisibility(View.GONE);
            remarkEt.setText(userInfo.getRemarks());
            teacherNameEt.setText(CommonUtils.getStr(userInfo.getNickName()));
            teacherLocationTv.setText(CommonUtils.getStr(userInfo.getProvince()) + CommonUtils.getStr(userInfo.getCity()) + CommonUtils.getStr(userInfo.getArea()));
            teacherSchollEt.setText(CommonUtils.getStr(userInfo.getSchool()));
            teacherGradeTv.setText(CommonUtils.getStr(userInfo.getGradeName()));
            teacherGoodAtSubjectsTv.setText(CommonUtils.getStr(userInfo.getSubjectName()));
            teacherEducationTimeEt.setText(CommonUtils.getStr(userInfo.getYears()));
            teacherQualificationTv.setText(CommonUtils.getStr(userInfo.getQualificationsName()));
            teacherPuTongHuaTv.setText(CommonUtils.getStr(userInfo.getMandarinName()));
            if (userInfo.getGender() == 1) {
                teacherSexRb.check(R.id.teacher_man_rbtn);
            } else if (userInfo.getGender() == 2) {
                teacherSexRb.check(R.id.teacher_women_rbtn);
            }
        }
    }

    private void showAddressDialog() {
        if (addressDialog == null) {
            addressDialog = new AddressDialog(this);
            addressDialog.setOnSelectListener((province, city, area, provincePosition, cityPosition, areaPosition) -> {
                userContentBean.getUserInfo().setProvince(province);
                userContentBean.getUserInfo().setCity(city);
                userContentBean.getUserInfo().setArea(area);
                if (type == Common.ApplyAnswer) {
                    answerLocationTv.setText(province + city + area);
                } else if (userContentBean.getUserInfo().getUserIdentity() == 1) {
                    studentLocationTv.setText(province + city + area);
                } else if (userContentBean.getUserInfo().getUserIdentity() == 2) {
                    teacherLocationTv.setText(province + city + area);
                }
                setConfrimBtnEnable();
            });
        }
        addressDialog.show();
    }

    private void showGradeDailog() {
        if (gradeDialog == null) {
            gradeDialog = new SelectWheelDialog(this, new ArrayList<>(gradeList));
            gradeDialog.setOnSelectListener((position, str) -> {
                GradeBean gradeBean = gradeList.get(position);
                userContentBean.getUserInfo().setGradeId(gradeBean.getGradeId());
                userContentBean.getUserInfo().setGradeName(gradeBean.getGradeName());
                if (type == Common.ApplyAnswer) {
                    answerGradeTv.setText(str);
                } else if (userContentBean.getUserInfo().getUserIdentity() == 1) {
                    studentGradeTv.setText(str);
                } else if (userContentBean.getUserInfo().getUserIdentity() == 2) {
                    teacherGradeTv.setText(str);
                }
                setConfrimBtnEnable();
            });
        }
        if (userContentBean.getUserInfo().getUserIdentity() == 1) {
            gradeDialog.setTitle(getResources().getString(R.string.select_grade));
        } else if (userContentBean.getUserInfo().getUserIdentity() == 2) {
            gradeDialog.setTitle(getResources().getString(R.string.select_education_grade));
        }
        gradeDialog.show();
    }

    private void showHierarchyDialog(TextView tv, List<CharSequence> list, int type) {
        if (hierarchyDialog == null) {
            hierarchyDialog = new SelectListDialog(this, list);
        }
        hierarchyDialog.setOnListSelectListener((position, str) -> {
            if (type == 1) {
                MandarinBeam mandarinBeam = mandarinBeams.get(position);
                userContentBean.getUserInfo().setMandarinId(mandarinBeam.getMandarinId());
                userContentBean.getUserInfo().setMandarinName(mandarinBeam.getMandarinName());
            } else if (type == 2) {
                QualificationBean qualificationBean = qualificationBeans.get(position);
                userContentBean.getUserInfo().setQualificationsName(qualificationBean.getQualificationsName());
                userContentBean.getUserInfo().setQualificationsId(qualificationBean.getQualificationsId());
            }
            setConfrimBtnEnable();
        });
        hierarchyDialog.setStringList(list);
        hierarchyDialog.show(tv);
    }

    private void showSubjectDialog() {
        if (subjectDialog == null) {
            subjectDialog = new SelectWheelDialog(this, new ArrayList<>(subjectList));
            subjectDialog.setTitle(getResources().getString(R.string.good_at_subjects_title));
            subjectDialog.setOnSelectListener((position, str) -> {
                SubjectBean subjectBean = subjectList.get(position);
                userContentBean.getUserInfo().setSubjectId(subjectBean.getSubjectId());
                userContentBean.getUserInfo().setSubjectName(subjectBean.getSubjectName());
                if (type == Common.ApplyAnswer) {
                    goodAtSubjectsTv.setText(subjectBean.getSubjectName());
                } else {
                    teacherGoodAtSubjectsTv.setText(subjectBean.getSubjectName());
                }
                setConfrimBtnEnable();
            });
        }
        subjectDialog.show();
    }

    private void setConfrimBtnEnable() {
        if (type == Common.ApplyAnswer) {
            if (answerNameEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (answerLocationTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (answerSchollEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (answerGradeTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (goodAtSubjectsTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (educationTimeEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (answerQualificationTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (puTongHuaTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (userContentBean.getUserInfo().getGender() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (remarkEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (TextUtils.isEmpty(userContentBean.getUserInfo().getHeadPic()) && TextUtils.isEmpty(localPath)) {
                confrimBtn.setEnabled(false);
                return;
            }
            confrimBtn.setEnabled(true);
        } else if (userContentBean.getUserInfo().getUserIdentity() == 1) {
            if (studentNicknameEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (studentGradeTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (studentLocationTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (studentSchollEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
           /* if (remarkEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }*/
          /*  if (TextUtils.isEmpty(userContentBean.getUserInfo().getHeadPic()) && TextUtils.isEmpty(localPath)) {
                confrimBtn.setEnabled(false);
                return;
            }*/
            if (userContentBean.getUserInfo().getGender() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            confrimBtn.setEnabled(true);
        } else if (userContentBean.getUserInfo().getUserIdentity() == 2) {
            if (teacherNameEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherLocationTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherSchollEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherGradeTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherGoodAtSubjectsTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherEducationTimeEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherQualificationTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (teacherPuTongHuaTv.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (userContentBean.getUserInfo().getGender() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (remarkEt.getText().toString().length() <= 0) {
                confrimBtn.setEnabled(false);
                return;
            }
            if (TextUtils.isEmpty(userContentBean.getUserInfo().getHeadPic()) && TextUtils.isEmpty(localPath)) {
                confrimBtn.setEnabled(false);
                return;
            }
            confrimBtn.setEnabled(true);
        }

    }

    @OnClick({R.id.student_grade_tv, R.id.student_location_tv, R.id.head_photo_iv, R.id.confrim_btn})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.student_grade_tv:
                break;
            case R.id.student_location_tv:
                break;
            case R.id.head_photo_iv:
                if (takePhotoDialog == null) {
                    takePhotoDialog = new TakePhotoDialog(this);
                }
                takePhotoDialog.show();
                break;
            case R.id.confrim_btn:
                if (!TextUtils.isEmpty(localPath)) {
                    mPresenter.uploadFile(localPath);
                } else {
                    updateUserInfo();
                }

                break;
        }
    }

    private void updateUserInfo() {
        UserInfo userInfo = userContentBean.getUserInfo();
        if (type == Common.ApplyAnswer) {
            String name = answerNameEt.getText().toString();
            userInfo.setNickName(name);
            userInfo.setRealName(name);
            userInfo.setSchool(answerSchollEt.getText().toString());
            userInfo.setYears(educationTimeEt.getText().toString());
            userInfo.setDescribe(remarkEt.getText().toString());
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("nickName", userInfo.getNickName());
            jsonObject.addProperty("realName", userInfo.getRealName());
            jsonObject.addProperty("province", userInfo.getProvince());
            jsonObject.addProperty("city", userInfo.getCity());
            jsonObject.addProperty("area", userInfo.getArea());
            jsonObject.addProperty("school", userInfo.getSchool());
            jsonObject.addProperty("gradeId", userInfo.getGradeId());
            jsonObject.addProperty("subjectId", userInfo.getSubjectId());
            jsonObject.addProperty("years", userInfo.getYears());
            jsonObject.addProperty("qualificationsId", userInfo.getQualificationsId());
            jsonObject.addProperty("mandarinId", userInfo.getMandarinId());
            jsonObject.addProperty("gender", userInfo.getGender());
            jsonObject.addProperty("describe", userInfo.getDescribe());
            jsonObject.addProperty("headPic", userInfo.getHeadPic());
            mPresenter.applyAnswer(jsonObject);
        } else if (userInfo.getUserIdentity() == 1) {
            String studentName = studentNicknameEt.getText().toString();
            userInfo.setNickName(studentName);
            userInfo.setRealName(studentName);
            userInfo.setSchool(studentSchollEt.getText().toString());
            userInfo.setRemarks(remarkEt.getText().toString());

            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("nickName", userInfo.getNickName());
            jsonObject.addProperty("realName", userInfo.getRealName());
            jsonObject.addProperty("gender", userInfo.getGender());
            jsonObject.addProperty("province", userInfo.getProvince());
            jsonObject.addProperty("city", userInfo.getCity());
            jsonObject.addProperty("area", userInfo.getArea());
            jsonObject.addProperty("school", userInfo.getSchool());
            jsonObject.addProperty("gradeId", userInfo.getGradeId());
            jsonObject.addProperty("remarks", userInfo.getRemarks());
            jsonObject.addProperty("headPic", userInfo.getHeadPic());
            mPresenter.updateUserInfo(jsonObject);
        } else if (userInfo.getUserIdentity() == 2) {
            String name = teacherNameEt.getText().toString();
            userInfo.setNickName(name);
            userInfo.setRealName(name);
            userInfo.setSchool(teacherSchollEt.getText().toString());
            userInfo.setYears(teacherEducationTimeEt.getText().toString());
            userInfo.setRemarks(remarkEt.getText().toString());
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("nickName", userInfo.getNickName());
            jsonObject.addProperty("realName", userInfo.getRealName());
            jsonObject.addProperty("province", userInfo.getProvince());
            jsonObject.addProperty("city", userInfo.getCity());
            jsonObject.addProperty("area", userInfo.getArea());
            jsonObject.addProperty("school", userInfo.getSchool());
            jsonObject.addProperty("gradeId", userInfo.getGradeId());
            jsonObject.addProperty("subjectId", userInfo.getSubjectId());
            jsonObject.addProperty("years", userInfo.getYears());
            jsonObject.addProperty("qualificationsId", userInfo.getQualificationsId());
            jsonObject.addProperty("mandarinId", userInfo.getMandarinId());
            jsonObject.addProperty("gender", userInfo.getGender());
            jsonObject.addProperty("remarks", userInfo.getRemarks());
            jsonObject.addProperty("headPic", userInfo.getHeadPic());
            mPresenter.updateUserInfo(jsonObject);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK) {
            switch (requestCode) {
                case TakePhotoRequestCode:
                    if (takePhotoDialog != null) {
                        localPath = takePhotoDialog.getTakePhotoPath();
                        GlideUtils.LoadImage(this, localPath, headPhotoIv);
                        setConfrimBtnEnable();
                    }
                    break;
                case PhotoAlbumRequestCode:
                    if (data != null) {
                        Uri uri = data.getData();
                        localPath = ImageUtils.uriToRealPath(this, uri);
                        GlideUtils.LoadImage(this, localPath, headPhotoIv);
                        setConfrimBtnEnable();
                    }
                    break;
            }
        }
    }

    @Override
    public void gradeListResult(List<GradeBean> gradeBeans) {
        gradeList = gradeBeans;
        if (gradeDialog != null) {
            gradeDialog.setMiddleList(new ArrayList<>(gradeList));
        }
    }

    @Override
    public void subjectListResult(List<SubjectBean> subjectList) {
        this.subjectList = subjectList;
        if (subjectDialog != null) {
            subjectDialog.setMiddleList(new ArrayList<>(this.subjectList));
        }
    }

    @Override
    public void qualificationsListResult(List<QualificationBean> qualificationBeans) {
        this.qualificationBeans = qualificationBeans;
    }

    @Override
    public void mandarinListResult(List<MandarinBeam> mandarinBeams) {
        this.mandarinBeams = mandarinBeams;
    }

    @Override
    public void updateUserInfoResult() {
        setResult(Common.MineDetailResultCode);
        finish();
    }

    @Override
    public void uploadFileResult(String url) {
        userContentBean.getUserInfo().setHeadPic(url);
        updateUserInfo();
    }

    @Override
    public void applyAnsweResult() {
        setResult(Common.MineDetailResultCode);
        finish();
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        setConfrimBtnEnable();
    }

    @Override
    public void afterTextChanged(Editable s) {

    }
}
